﻿class CPosition {
    X: number;
    Y: number;

    constructor() {
        this.SetRandomly();
    }

    Move(direction: CDirection, speed: number) {

        this.X += (direction.X);
        this.Y += (direction.Y);

        if (this.X > 100)
            this.X -= 100;

        if (this.Y > 100)
            this.Y -= 100;

        if (this.X < 0)
            this.X += 100;

        if (this.Y < 0)
            this.Y += 100;
    }

    SetRandomly() {
        this.X = Math.random() * 100;                // 0 - 100
        this.Y = Math.random() * 100;                // 0 - 100
    }

    Distance(otherPos: CPosition): number {

        var distX = Math.abs(this.X - otherPos.X);
        var distY = Math.abs(this.Y - otherPos.Y);
        return Math.sqrt(Math.pow(distX, 2) + Math.pow(distY, 2));

    }

}